<title>棋局列表 - {:getSettingOptionsCache('base.web_site_title') ?: '后台管理系统模板'}</title>
<!--表格插件css-->
<link rel="stylesheet" href="{:HTTP_STATIC_ADMIN_CDN_URL}js/bootstrap-table/bootstrap-table.min.css">
<link rel="stylesheet" type="text/css" href="{:HTTP_STATIC_ADMIN_CDN_URL}css/style.min.css">

<div class="container-fluid">
    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <header class="card-header">
                    <div class="card-title">棋局列表</div>
                </header>
                <div class="card-body">
                    <form id="searchForm" class="row row-cols-lg-auto g-3 align-items-center">
                        <input type="hidden" value="{:values('match_id')}" name="match_id" />
                        <div class="col-12 mb-1">
                            <div class="input-group">
                                <span class="btn btn-default disabled-button-pointer">房间编号</span>
                                <input type="text" class="form-control" autocomplete="off" value="{:values('room_id')}" id="room_id" name="room_id" placeholder="请输入房间编号" "{:values('match_id') ? 'readonly' : ''}" />
                            </div>
                        </div>
                        <div class="col-12 mb-1">
                            <div class="input-group">
                                <div class="input-group-prepend search-bar">
                                    <input type="hidden" name="uid_keyword_field" class="search-field" value="uid">
                                    <button class="btn search-btn btn-default dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">房主id</button>
                                    <div class="dropdown-menu">
                                        <a class="dropdown-item" href="javascript:void(0)" data-field="uid">房主id</a>
                                        <a class="dropdown-item" href="javascript:void(0)" data-field="opposite_uid">玩家id</a>
                                    </div>
                                </div>
                                <input type="text" class="form-control" autocomplete="off" value="" id="uid_keyword_value" name="uid_keyword_value" placeholder="请输入关键词">
                            </div>
                        </div>
                        <div class="col-12 mb-1">
                            <button type="submit" class="btn btn-default me-1 sreach-all"><i class="mdi mdi-magnify"></i> 搜索</button>
                        </div>
                    </form>
                    <table id="table"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript" src="{:HTTP_STATIC_ADMIN_CDN_URL}js/layer/src/layer.js"></script>
<!--加载插件-->
<script type="text/javascript" src="{:HTTP_STATIC_ADMIN_CDN_URL}js/lyear-loading.js"></script>
<!--表格插件js-->
<script src="{:HTTP_STATIC_ADMIN_CDN_URL}js/bootstrap-table/bootstrap-table.js"></script>
<script src="{:HTTP_STATIC_ADMIN_CDN_URL}js/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>

<script>
    //转换成数组
    let chess = {
        1: {
            name: '白棋',
            color: 'bg-light text-dark shadow-sm'
        },
        2: {
            name: '黑棋',
            color: 'bg-dark'
        },
        3: {
            name: '无棋',
            color: 'bg-danger'
        }
    };
    let withdraw = {
        1: {
            name: '是',
            color: 'bg-success'
        },
        2: {
            name: '否',
            color: 'bg-secondary'
        }
    };
    const requestUrl = "{:url('/admin/match/list')}";
    const columns = [{
        field: 'id',
        title: '编号',
        // 使用[align]，[halign]和[valign]选项来设置列和它们的标题的对齐方式。
        // h表示横向，v标识垂直
        align: 'center',
        switchable: false,
        // 列的宽度
        width: 5,
        // 宽度单位
        widthUnit: 'rem'
    }, {
        field: 'room_id',
        title: '房间编号',
        align: 'center',
        width: 8,
        // 宽度单位
        widthUnit: 'rem',
    }, {
        field: 'username',
        title: '房主',
        align: 'center',
        width: 10,
        // 宽度单位
        widthUnit: 'rem',
    }, {
        field: 'opposite_username',
        title: '玩家',
        align: 'center',
        width: 10,
        // 宽度单位
        widthUnit: 'rem',
    }, {
        field: 'x',
        title: '坐标(x, y)',
        align: 'center',
        width: 6,
        // 宽度单位
        widthUnit: 'rem',
        formatter: (value, row, index) => {
            return value + ', ' + row.y;
        }
    }, {
        field: 'chess',
        title: '棋子颜色',
        width: 6,
        // 宽度单位
        widthUnit: 'rem',
        align: 'center',
        formatter: function (value, row, index) {
            //如果不存在对象里则使用默认
            value = chess[value] ? value : 3;
            return '<span class="badge ' + chess[value].color + '">' + chess[value].name + '</span>';
        }
    },  {
        field: 'withdraw',
        title: '是否悔棋',
        width: 6,
        // 宽度单位
        widthUnit: 'rem',
        align: 'center',
        formatter: function (value, row, index) {
            value = withdraw[value] ? value : 2;
            return '<span class="badge ' + withdraw[value].color + '">' + withdraw[value].name + '</span>';
        }
    },  {
        field: 'addtime',
        title: '落子时间',
        width: 10,
        // 宽度单位
        widthUnit: 'rem',
        align: 'center',
        formatter: (value, row, index) => {
            return makeData(value);
        }
    }];
</script>
<script type="text/javascript" src="/static/admin/js/common/table.js"></script>
<script>
    $(function () {
        $('.sreach-all').click(function () {
            refreshTable();
        });

        $('#searchForm').submit(function(){
            event.preventDefault();
        });
    });

    //下拉框更新样式
    $('.exampleSelect').each(function() {
        var $this = $(this);
        $this.lyearSelect({
            width: $this.data('width') ? $this.data('width') : '', // width示例：75px、50%
            placeholder: $this.data('placeholder') ? $this.data('placeholder') : '请选择',
            search: $this.data('search') ? $this.data('search') : false,
        });
    });

    //下拉选择搜索项
    $('.search-bar .dropdown-menu a').click(function() {
        $(this).parents('.search-bar').find('.search-field').val(($(this).data('field') || ''));
        $(this).parents('.search-bar').find('.search-btn').html($(this).text());
    });
</script>